<?php
class Blog
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
		$this->_db = Zend_Registry::get('db');
    }
    public function addblog($insertarr)
    {

         try
         {
             $sql= " insert  into aml_blogcontent(
                    title ,
                    alias ,
                    full_text ,
                    catid ,
                    created_by_alias ,
                    state ,
                    publish_up ,
                    publish_down ,
                    access ,
                    metadesc,
                    metakey ) values
                    (
                    
                    '{$insertarr['title']}',
                    '{$insertarr['alias']}',
                    '{$insertarr['full_text']}',
                    {$insertarr['catid']},
                    '{$insertarr['created_by_alias']}',
                    {$insertarr['state']},
                    '{$insertarr['publish_up']}',
                    '{$insertarr['publish_down']}',
                    {$insertarr['access']},
                    '{$insertarr['metadsc']}',
                    '{$insertarr['metakey']}'
                    )";
            
           //echo $sql;exit;
              if($this->_db->exec($sql))
              {
                  return true;
              }
              else
              {
                  return false;
              }
         }
         catch(Exception $e)
         {
              echo 'Caught exception: ',  $e->getMessage(), "\n";
             return false;
         }
    }

     public function editblog($insertarr)
    {

         try
         {
             $sql= " update  aml_blogcontent
                   set  title='{$insertarr['title']}' ,
                    alias='{$insertarr['alias']}' ,
                    full_text='{$insertarr['full_text']}' ,
                    catid={$insertarr['catid']} ,
                    created_by_alias='{$insertarr['created_by_alias']}' ,
                    state={$insertarr['state']} ,
                    publish_up='{$insertarr['publish_up']}' ,
                    publish_down='{$insertarr['publish_down']}' ,
                    access={$insertarr['access']} ,
                    metadesc='{$insertarr['metadesc']}',
                    metakey='{$insertarr['metakey']}'   where id={$insertarr['id']}
                    ";
    
              if($this->_db->exec($sql))
              {
                  return true;
              }
              else
              {
                  return false;
              }
         }
         catch(Exception $e)
         {
              echo 'Caught exception: ',  $e->getMessage(), "\n";
             return false;
         }
    }
    public function listblogs($insertarr)
    {
        $sql=" select * from aml_blogcontent";
        return $this->_db->fetchAll($sql);

    }


      public function getblog($id)
    {
        $sql=" select * from aml_blogcontent where id={$id}";
        return $this->_db->fetchRow($sql);

    }

    public  function deleteblog($id)
    {
         $sql=" delete from aml_blogcontent where id={$id}";

           if($this->_db->exec($sql))
              {
                  return true;
              }
              else
              {
                  return false;
              }
    }
    public function changeBlogStatus($id)
    {
         $sql_getstatus = "SELECT state
				FROM aml_blogcontent
				WHERE  id = " . $id;

		$result = $this->_db->fetchRow($sql_getstatus);
		$status = $result['state'];

		if($status == 1) {
			$change_status = 0;
		} else {
			$change_status = 1;
		}

		$sql_updatestatus = "UPDATE aml_blogcontent
							 SET state = " . $change_status . "
							 WHERE  id = " . $id;
               // echo $sql_updatestatus;
		$this->_db->exec($sql_updatestatus);
    }
	
	
}